- Console
- Change Kernel…
- Clear Console Cells
- Close and Shut Down…
- Insert Line Break
- Interrupt Kernel
- New Console
- Restart Kernel…
- Run Cell (forced)
- Run Cell (unforced)
- Show All Kernel Activity
- Extension Manager
- Enable Extension Manager
- File Operations
- Autosave Documents
- DownloadDownload the file to your computer
- Open from Path…Open from path
- Reload Notebook from DiskReload contents from disk
- Revert Notebook to CheckpointRevert contents to previous checkpoint
- Save NotebookSave and create checkpoint⌘ S
- Save Notebook As…Save with new path⇧ ⌘ S
- Show Active File in File Browser
- Trust HTML File
- Help
- Jupyter Reference
- JupyterLab FAQ
- JupyterLab Reference
- Launch Classic Notebook
- Markdown Reference
- Reset Application State
- Image Viewer
- Flip image horizontallyH
- Flip image verticallyV
- Invert ColorsI
- Reset Image0
- Rotate Clockwise]
- Rotate Counterclockwise[
- Zoom In=
- Zoom Out-
- Kernel Operations
- Shut Down All Kernels…
- Launcher
- New Launcher
- Main Area
- Activate Next Tab⌃ ⇧ ]
- Activate Next Tab Bar⌃ ⇧ .
- Activate Previous Tab⌃ ⇧ [
- Activate Previous Tab Bar⌃ ⇧ ,
- Activate Previously Used Tab⇧ ⌘ '
- Close All Other Tabs
- Close All Tabs
- Close Tab⌥ W
- Close Tabs to Right
- Find Next⌘ G
- Find Previous⇧ ⌘ G
- Find…⌘ F
- Log OutLog out of JupyterLab
- Presentation Mode
- Show Left Sidebar⌘ B
- Show Log Console
- Show Status Bar
- Shut DownShut down JupyterLab
- Single-Document Mode⇧ ⌘ D
- Notebook Cell Operations
- Change to Code Cell TypeY
- Change to Heading 11
- Change to Heading 22
- Change to Heading 33
- Change to Heading 44
- Change to Heading 55
- Change to Heading 66
- Change to Markdown Cell TypeM
- Change to Raw Cell TypeR
- Clear Outputs
- Collapse All Code
- Collapse All Outputs
- Collapse Selected Code
- Collapse Selected Outputs
- Copy CellsC
- Cut CellsX
- Delete CellsD, D
- Disable Scrolling for Outputs
- Enable Scrolling for Outputs
- Expand All Code
- Expand All Outputs
- Expand Selected Code
- Expand Selected Outputs
- Extend Selection Above⇧ K
- Extend Selection Below⇧ J
- Extend Selection to Bottom⇧ End
- Extend Selection to Top⇧ Home
- Insert Cell AboveA
- Insert Cell BelowB
- Merge Selected Cells⇧ M
- Move Cells Down
- Move Cells Up
- Paste Cells Above
- Paste Cells and Replace
- Paste Cells BelowV
- Redo Cell Operation⇧ Z
- Run Selected Cells⇧ Enter
- Run Selected Cells and Don't Advance⌃ Enter
- Run Selected Cells and Insert Below⌥ Enter
- Run Selected Text or Current Line in Console
- Select Cell AboveK
- Select Cell BelowJ
- Split Cell⌃ ⇧ -
- Undo Cell OperationZ
- Notebook Operations
- Change Kernel…
- Clear All Outputs
- Close and Shut Down
- Deselect All Cells
- Enter Command Mode⌃ M
- Enter Edit ModeEnter
- Export Notebook to Asciidoc
- Export Notebook to Executable Script
- Export Notebook to HTML
- Export Notebook to LaTeX
- Export Notebook to Markdown
- Export Notebook to PDF
- Export Notebook to ReStructured Text
- Export Notebook to Reveal.js Slides
- Export Notebook to Webpdf
- Interrupt Kernel
- New Console for Notebook
- New NotebookCreate a new notebook
- Reconnect To Kernel
- Render All Markdown Cells
- Restart Kernel and Clear All Outputs…
- Restart Kernel and Run All Cells…
- Restart Kernel and Run up to Selected Cell…
- Restart Kernel…
- Run All Above Selected Cell
- Run All Cells
- Run Selected Cell and All Below
- Select All Cells⌘ A
- Toggle All Line Numbers⇧ L
- Trust Notebook
- Settings
- Advanced Settings Editor⌘ ,
- Show Contextual Help
- Show Contextual HelpLive updating code documentation from the active kernel⌘ I
- Terminal
- Decrease Terminal Font Size
- Increase Terminal Font Size
- New TerminalStart a new terminal session
- Refresh TerminalRefresh the current terminal session
- Use Dark Terminal ThemeSet the terminal theme
- Use Inherit Terminal ThemeSet the terminal theme
- Use Light Terminal ThemeSet the terminal theme
- Text Editor
- Decrease Font Size
- Increase Font Size
- Indent with Tab
- New Markdown FileCreate a new markdown file
- New Text FileCreate a new text file
- Spaces: 1
- Spaces: 2
- Spaces: 4
- Spaces: 8
- Theme
- Decrease Code Font Size
- Decrease Content Font Size
- Decrease UI Font Size
- Increase Code Font Size
- Increase Content Font Size
- Increase UI Font Size
- Theme Scrollbars
- Use JupyterLab Dark Theme
- Use JupyterLab Light Theme
xxxxxxxxxximport plotly.express as pxxxxxxxxxxxxxxxxxxxxxKernel Sessions
- distractions.ipynb
- notebook.ipynb
- poor driving.ipynb
- introduction.ipynb
- Untitled.ipynb
Terminal Sessions
- notebook.ipynb
- introduction.ipynb
- Untitled.ipynb
- distractions.ipynb
- poor driving.ipynb
- aux.py
- contributing_factors.csv
JupyterLab viewer for GitHub repositories
The JupyterLab extension providing Jupyter widgets.
A JupyterLab extension for version control using git
A JupyterLab extensions for rendering Plotly Dash apps
Matplotlib Jupyter Interactive Widget
A JupyterLab extension for showing Notebook diffs.
The plotly JupyterLab extension
- JupyterLab - Application Utilities
Jupyter server extension to supervise and proxy web services
JupyterLab - Translation services
GeoJSON renderer for JupyterLab
Fasta renderer for JupyterLab
Pull Requests for JupyterLab- An extension for manipulating tags in cell metadata
Cloud storage with JupyterLab through Google Drive- An extension for manipulating tags in cell metadata
- JupyterLab - Debugger Extension
- JupyterLab - Table of Contents widget extension
- JupyterLab - Translation services
- JupyterLab - Debugger Extension
KaTeX math renderer for JupyterLab
A JupyterLab extension for Metadata Service
JupyterLab extension for running LaTeX
A Jupyter widget for interfacing with MIDI controllers.- Show a random NASA Astronomy Picture of the Day.
Datasets as first class entities in Juptyerlab.
Open and explore (very large) HDF5 files in Jupyterlab.
Language Server Protocol integration for JupyterLab
a local versioning logging tool for jupyterlab notebooks- Jump to definition of a variable or function in JupyterLab
bqplot
JupyterLab extension - Visual editor to build Notebook pipelines
A JupyterLab extension for embedding drawio / mxgraph.
A side panel providing information and controls to run Apache Beam notebooks interactively.
Cognos Dashboard Embedded for JupyterLab
Integrate 'react-toastify' nicely in JupyterLab.- A JupyterLab extension for Dask.
- TileDB notebook extension to prompt user for notebook options
JupyterLab 2.x Solarized Dark extension.
EXPERIMENTAL: Save, reuse, and share code snippets using JupyterLab Code Snippets
Darcula theme for JupyterLab. Modelled after the classic Intellij theme.
A Jupyterlab extension to make, download and extract archive files.
A vCDAT extension for JupyterLab.
A Jupyter extension for rendering Bokeh content.- Interactive Jupyter genome browser
A JupyterLab extension for performing Vega transforms lazily using Ibis.
Display cell timings in Jupyter Lab
nglview-js-widgets
Manage your conda environments from JupyterLab
jupyter - threejs bridge- JupyterLab viewer for GitHub repositories
JupyterLab viewer for Thredds catalog and ESGF
JupyterLab extension - View and edit metadata
Make headings collapsible like the old Jupyter notebook extension and like e.g. mathematica notebooks.
A JupyterLab extension for creating and editing Plotly charts
A package which provides a tutorial manager for incorporating interactive tutorials within JupyterLab.
Save Jupyter Notebooks as Scripts or Markdown files that work well with version control & external text editors
VSCode Horizon Theme port for JupyterLab
Jupyter widgets base for Vue libraries
Interactive Jupyter widgets to visualize images in 2D and 3D
A custom widget for returning mouse and keyboard events to Python
React JSON Schema Form for JupyterLab- Code cell vim bindings
- Automatically run and/or hide cells when opening a Jupyter notebook
A JupyterLab theme extension inspired by Tailwind CSS.
A JupyterLab extension for version control using git
Kite integration for JupyterLab- Create Python Files from JupyterLab
- JupyterLab extension for browsing S3-compatible object storage
JupyterLab extension - Reusable code snippets for your Notebook and Python Scripts
A JupyterLab extension for rendering Errors with a copy/paste button and expand/collapse
JupyterLab extension - Run python scripts using a kernel runtime
Hale Theme for Jupyter Lab 3.x. Inspired by Night Owl.
A JupyterLab extension for version control using git
ElkJS widget for Jupyter
A Jupyter Lab extension for inspecting messages to/from a kernel
A cell toolbar for JupyterLab.- VPython extension for JupyterLab
- JupyterLab viewer for GitLab repositories
AAS WorldWide Telescope in JupyterLab
A simple and dark theme for Jupyter Lab
JupyterLab LTI extension for the Canvas LMS.
JupyterLab extension to show a flash effect when a cell is executed
A port of the City Lights theme for JupyterLab
AAS WorldWide Telescope from Python
A enhanced launcher for JupyterLab
JupyterLab extension for SoS workflow engine and polyglot notebook- QControl3 integration for jupyterlab
Jupyterlab extension to show notebook cell completion browser notifications- JupyterLab extension to toggle the theme in the Top Bar area
Create rich adata annotations in jupyter notebooks.
A annotation Jupyter Widget based on Annotorius.
A flat, 80's neon inspired theme for JupyterLab 3.x.
igv-jupyterlab is an extension for Jupyter Lab and traditional Jupyter Notebooks which wraps igv.js.
A JupyterLab UI Tour.- Jupyter widgetds library for webgui js visualization library'
- A Custom Jupyter Widget Library
An JupyterLab extension to handle project and files template.- OpenBayes Theme
Control JupyterLab from Python notebooks
Sublime notebook cell binding for JupyterLab- OpenBayes Introduction
- Adds a spreadsheet viewer to JupyterLab
Sublime notebook cell binding for JupyterLab
A JupyterLab extension for embedding interactive drawio / mxgraph diagrams.
Code formatter for JupyterLab.
JupyterLab offline-notebook extension.
jupyter - leaflet bridge
JupyterLab extension - Run R scripts using a kernel runtime
JupyterLab extension - Elyra theme- experimental Jupyter widgets for HTML5
An extension for JupyterLab which provides an entry point, functions and defaults for the @cdat/jupyterlab-tutorial package.
An extension for manipulating tags in cell metadata- experimental Jupyter widgets for the Lumino DataGrid
- Experimental widgets for JupyterLab
- experimental Jupyter widgets for JSON Schema Form
- Experimental Jupyter widgets for JSON and evented transformations
Use HERE Maps API for JavaScript in your Jupyter Notebook.- experimental Jupyter widgets for JSON-E
- experimental Jupyter widgets for working with data in revision control
- experimental Jupyter widgets for SVG
- experimental Jupyter widgets for Nunjucks templates
- Jupyter widget for Vipster
Sets the active widget name (e.g. jupyter notebook name) as the browser tab name.
EXPERIMENTAL: JupyterLab Tabular Data Editor for CSV files- Neptune Labs extension for Jupyter
Manage your conda environments from JupyterLab
An extension for manipulating tags in cell metadata- experimental Jupyter widgets for YAML
- experimental Jupyter widgets for JSON-LD
Jupyter widgets based on vuetify UI components
Parameterized files and folders for JupyterLab- Extension to display transient_display_data in Jupyter Lab
A spell checker for JupyterLab.- A JupyterLab extension providing a set of widgets to help facilitate reuse of large datasets across widgets.
A JupyterLab preview extension for Voilà
DO NOT USE: see ipycallback instead. This is for testing purposes. Use this widget to allow client side (javascript) to trigger event on the server side (python)
Integration with Odahu Platform
Allows toggling of code cells to execute automatically after opening a notebook.
A JupyterLab extension to display, filter and allow download of notebooks from the Precision Health Cloud Tool Registry.- A Custom Jupyter Widget Library
A Cytoscape Jupyter Widget
Jupyter widget for rendering deck.gl in a Jupyter notebook
Jupyter notebook extension to selectively hide code, prompts and outputs with PDF and HTML exporting support.- The Mito Spreadsheet
Use this widget to allow client side (javascript) to trigger event on the server side (python)
Jupyter Lab extension to monitor Apache Spark Jobs- greenflow Jupyterlab extension
A JupyterLab extension.
A JupyterLab Glue DataBrew extension.- Widget test
- JupyterLab spreadsheet (csv/tsv) editor
JupyterLab extension of executing the scripts
Video Chat with peers inside JupyterLab
Companion Jupyter extension for ContainDS
A JupyterLab extension for rendering PyViz content
Jupyter Lab extension to monitor Apache Spark Jobs- Show an intro widget in the laucher that displays ENKI information.
- A file browser implementation for accessing shared resources
A JupyterLab extension to control the configurable-http-proxy of JupyterHub.- Pitaya Smoothie in JupyterLab: a dark theme inspired by 2018 Pantone of the Year. Designed for low-light condition and colorblindness tested.
UpSet.js is a re-implementation of UpSetR to create interactive set visualizations for more than three sets
BeakerX: Beaker EasyForms, Magics, Plots and Spark Extension for Jupyter Lab 2.x
Generate model cards for machine learning models
gQuant Jupyterlab extension
A JupyterLab extension for annotating machine learning training sets using Prodigy
AlgorithmX Jupyter widget.
Stixview library widget for Jupyter- A Jupyter Widget for Kodexa
A JupyterLab extension for rendering wav files.- Extends JupyterLab to display the state of Rigetti Forest software and services
Jupyter lab extension to add keyboard shortcuts for altering cell slide mode.
A JupyterLab extension.
A Cytoscape Widget for Common Lisp Jupyter
Provide arbitrary shortcuts for apps in JupyterLab
A simple and dark theme for Jupyter Lab- no desc
Emacs keybindings inside the notebook cells of JupyterLab.
Interactively create and customize dashboards in JupyterLab
Dracula Theme- A JupyterLab theme extension, taking after Atom's One Dark theme
- BabylonJS widget
- Syntax highlighting for KatScript within JupyterLab.
A JupyerLab extension giving network filesystem interface over IRODS.
A JupyterLab extension to interface with the Slurm workload manager.
JupyterLab extension to show an interactive dependency graph of the installed plugins
Connect to JACDAC devices from JupyterLab
JupyterLab Top Bar interface- A JupyterLab theme extension for youCANdoThermodynamics library
- A JupyterLab theme extension.
- A JupyterLab theme extension.
- A JupyterLab extension for cell-by-cell testing and linting of notebooks.
What-If Tool jupyter widget
A Jupyter widgets library for time and datetime pickers- A JupyterLab theme extension.
- A JupyterLab theme extension.
Insert text via shortcut keys in Jupyter Lab.- A JupyterLab theme extension.
- A JupyterLab theme extension.
- A JupyterLab theme extension.
- A JupyterLab theme extension.
A widget library for scales
A full IDE build of VSCode's One Dark Pro theme for JupyterLab- A JupyterLab theme extension.
- filebrowser overwrite
- A JupyterLab theme extension.
- metapackage for building @deathbeds/wxyz (probably won't install)
A JupyterLab extension for showing Notebook diffs.- A JupyterLab theme extension which provides the Purple Please theme, a beautiful theme that's easy on the eyes.
BeakerX: Beaker TableDisplay Extension for Jupyter Notebook and Lab- A glowing 80s theme based on Synthwave '84 and JupyterLab's Neon Night theme by yeebc
A Jupyter widget library for dynamically creating spinning activity indicators
A Kekule widget for Common Lisp Jupyter
JupyterLab extension to display arbitrary text in the top bar- A Custom Jupyter Widget Library
- A Monokai++ theme extension for JupyterLab
3D visualization library- An unofficial port of OneDark theme for JupyterLab.
Quirkshop JupyterLab3 React
Push to Kyso from JupyterLab
NGSolve Jupyter Widget Library- Incorporates Globus functionality
BeakerX: Beaker TableDisplay Extension for Jupyter Notebook and Lab
A Custom Jupyter Widget Library
JupyterLab extension to expose the top bar space
NeuroMynerva extension for FlyBrainLab
A JupyterLab extension that populates notebooks with URL parameters- Help panel for SWAN
Turtle implemention for Jupyter Notebook- SandDance data exploration Jupyter Widget
- Hello world for widgets!
Variable inspector extension for JupyterLab- JupyterLab openBIS extension
Notebook templates- azureml widgets
- JupyterLab Auth
- JupyterLab Auth
Generic Jupyter/IPython widget implementation that will support many types of javascript libraries and interactions.- for lowrisk
This is a simple jupyter widget for kepler.gl, an advanced geo-spatial visualization tool, to render large-scale interactive maps.
BeakerX: Beaker EasyForms, Magics, Plots and Spark Extension for Jupyter Lab 1.2.x
an unofficial Georgia Tech theme for JupyterLab
JupyterLab extension for uploading to Zenodo- Variable inspector extension for JupyterLab
Collapses code cells in jupyterlab
A ngl Widget for Common Lisp Jupyter- Accompanies the EPI2ME labs experience. Not for general use.
A resizable box widget for Common Lisp Jupyter- A JupyterLab extension.
Jupyter Widget using glvis-js
A JupyterLab extensions, which adds CodeMirror mode for Robot Framework syntax
xxxxxxxxxxxxxxxxxxxxAbout the Data (from here)¶
The Motor Vehicle Collisions crash table contains details on the crash event. Each row represents a crash event. The Motor Vehicle Collisions data tables contain information from all police reported motor vehicle collisions in NYC. The police report (MV104-AN) is required to be filled out for collisions where someone is injured or killed, or where there is at least $1000 worth of damage (https://www.nhtsa.gov/sites/nhtsa.dot.gov/files/documents/ny_overlay_mv-104an_rev05_2004.pdf). It should be noted that the data is preliminary and subject to change when the MV-104AN forms are amended based on revised crash details.For the most accurate, up to date statistics on traffic fatalities, please refer to the NYPD Motor Vehicle Collisions page (updated weekly) or Vision Zero View (updated monthly).
Due to success of the CompStat program, NYPD began to ask how to apply the CompStat principles to other problems. Other than homicides, the fatal incidents with which police have the most contact with the public are fatal traffic collisions. Therefore in April 1998, the Department implemented TrafficStat, which uses the CompStat model to work towards improving traffic safety. Police officers complete form MV-104AN for all vehicle collisions. The MV-104AN is a New York State form that has all of the details of a traffic collision. Before implementing Trafficstat, there was no uniform traffic safety data collection procedure for all of the NYPD precincts. Therefore, the Police Department implemented the Traffic Accident Management System (TAMS) in July 1999 in order to collect traffic data in a uniform method across the City. TAMS required the precincts manually enter a few selected MV-104AN fields to collect very basic intersection traffic crash statistics which included the number of accidents, injuries and fatalities. As the years progressed, there grew a need for additional traffic data so that more detailed analyses could be conducted. The Citywide traffic safety initiative, Vision Zero started in the year 2014. Vision Zero further emphasized the need for the collection of more traffic data in order to work towards the Vision Zero goal, which is to eliminate traffic fatalities. Therefore, the Department in March 2016 replaced the TAMS with the new Finest Online Records Management System (FORMS). FORMS enables the police officers to electronically, using a Department cellphone or computer, enter all of the MV-104AN data fields and stores all of the MV-104AN data fields in the Department’s crime data warehouse. Since all of the MV-104AN data fields are now stored for each traffic collision, detailed traffic safety analyses can be conducted as applicable.
xxxxxxxxxximport numpy as npimport pandas as pdfrom sklearn.neighbors import NearestNeighborsfrom aux import *import timet1 = time.time()df = pd.read_csv('Motor_Vehicle_Collisions_Crashes.csv')df = df.loc[~df['LOCATION'].isna()]df = df.loc[~(df['LOCATION'] == '(0.0, 0.0)')]df['ZIP CODE'] = df['ZIP CODE'].astype(str).replace(' ','nan').astype(float)df = haversine_KNN_impute(df, 'ZIP CODE')df = haversine_KNN_impute(df, 'BOROUGH')df['ZIP CODE'] = df['ZIP CODE'].astype(int)#Extract the contributing factors and vehicle types.df = extract_contributing_factors(df)df = extract_vehicle_types(df)t2 = time.time()print(f'Done doing the preprocessing. Time elapsed {t2-t1} seconds.')/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py:3156: DtypeWarning: Columns (3) have mixed types.Specify dtype option on import or set low_memory=False. interactivity=interactivity, compiler=compiler, result=result)
Done doing the preprocessing. Time elapsed 148.61166620254517 seconds.
xxxxxxxxxx| CRASH DATE | CRASH TIME | BOROUGH | ZIP CODE | LATITUDE | LONGITUDE | LOCATION | ON STREET NAME | CROSS STREET NAME | OFF STREET NAME | ... | CONTRIBUTING FACTOR VEHICLE 5 | COLLISION_ID | VEHICLE TYPE CODE 1 | VEHICLE TYPE CODE 2 | VEHICLE TYPE CODE 3 | VEHICLE TYPE CODE 4 | VEHICLE TYPE CODE 5 | CONTRIBUTING FACTORS (SPECIFIC) | CONTRIBUTING FACTORS (GENERAL) | VEHICLE TYPES | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 41 | 03/12/2021 | 1:55 | BROOKLYN | 11226 | 40.650913 | -73.947490 | (40.650913, -73.94749) | NaN | NaN | 3205 CHURCH AVENUE | ... | NaN | 4398634 | DUMP TRUCK | Sedan | NaN | NaN | NaN | Passing Too Closely | Poor Driving | Car, Truck |
| 55 | 03/06/2021 | 16:00 | BROOKLYN | 11217 | 40.682010 | -73.978360 | (40.68201, -73.97836) | NaN | NaN | 385 BERGEN STREET | ... | NaN | 4396634 | Sedan | NaN | NaN | NaN | NaN | Passing or Lane Usage Improper | Poor Driving | Car |
| 83 | 02/23/2021 | 15:10 | MANHATTAN | 10025 | 40.797220 | -73.969930 | (40.79722, -73.96993) | BROADWAY | NaN | NaN | ... | NaN | 4394003 | Van | NaN | NaN | NaN | NaN | Failure to Yield Right-of-Way | Poor Driving | Van |
| 85 | 02/22/2021 | 13:16 | BRONX | 10472 | 40.830975 | -73.852670 | (40.830975, -73.85267) | CROSS BRONX EXPY | NaN | NaN | ... | NaN | 4395641 | PK | Carry All | NaN | NaN | NaN | Following Too Closely | Poor Driving | Car, Truck |
| 86 | 02/22/2021 | 5:20 | QUEENS | 11379 | 40.712296 | -73.889540 | (40.712296, -73.88954) | NaN | NaN | 67-36 METROPOLITAN AVENUE | ... | NaN | 4394250 | Bus | Station Wagon/Sport Utility Vehicle | NaN | NaN | NaN | Following Too Closely | Poor Driving | Bus, Car |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1766603 | 07/01/2012 | 20:00 | STATEN ISLAND | 10306 | 40.552904 | -74.136560 | (40.5529042, -74.13656) | REDGRAVE AVENUE | DURANT AVENUE | NaN | ... | NaN | 293146 | SPORT UTILITY / STATION WAGON | PASSENGER VEHICLE | NaN | NaN | NaN | Turning Improperly | Poor Driving | Car, Car |
| 1766619 | 07/01/2012 | 10:11 | MANHATTAN | 10002 | 40.720477 | -73.989718 | (40.7204773, -73.9897185) | ALLEN STREET | RIVINGTON STREET | NaN | ... | NaN | 12177 | PASSENGER VEHICLE | PASSENGER VEHICLE | NaN | NaN | NaN | Failure to Yield Right-of-Way | Poor Driving | Car, Car |
| 1766623 | 07/01/2012 | 16:20 | BROOKLYN | 11213 | 40.668785 | -73.947817 | (40.6687847, -73.9478174) | UNION STREET | NEW YORK AVENUE | NaN | ... | NaN | 152368 | OTHER | PASSENGER VEHICLE | NaN | NaN | NaN | Driver Inexperience | Poor Driving | Car, Other |
| 1766626 | 07/01/2012 | 16:49 | MANHATTAN | 10024 | 40.791468 | -73.974106 | (40.7914677, -73.9741062) | BROADWAY | WEST 91 STREET | NaN | ... | NaN | 57556 | UNKNOWN | NaN | NaN | NaN | NaN | Backing Unsafely | Poor Driving | Unknown |
| 1766633 | 07/01/2012 | 15:00 | QUEENS | 11364 | 40.750591 | -73.778117 | (40.7505908, -73.7781175) | 201 STREET | 50 AVENUE | NaN | ... | NaN | 259355 | PASSENGER VEHICLE | PASSENGER VEHICLE | NaN | NaN | NaN | Failure to Yield Right-of-Way | Poor Driving | Car, Car |
430693 rows × 32 columns
xxxxxxxxxxWhy does it happen?¶
xxxxxxxxxxpd.read_csv('contributing_factors.csv',sep=';')['General'].unique()array(['Unspecified', 'Distraction', 'Poor Driving', 'Other Vehicular',
'Physical Disability', 'Driver Behavior', 'Physical Surroundings',
'Substance Abuse', 'Defective Car', 'Electronic Defective',
'Phone'], dtype=object)xxxxxxxxxxdf['CONTRIBUTING FACTORS (GENERAL)'].unique()array(['', 'Physical Surroundings', 'Distraction', 'Poor Driving',
'Other Vehicular, Other Vehicular', 'Driver Behavior',
'Other Vehicular', 'Substance Abuse', 'Defective Car',
'Physical Disability', 'Distraction, Poor Driving',
'Distraction, Distraction', 'Driver Behavior, Driver Behavior',
'Distraction, Driver Behavior',
'Physical Surroundings, Poor Driving',
'Other Vehicular, Poor Driving', 'Poor Driving, Poor Driving',
'Other Vehicular, Physical Surroundings',
'Driver Behavior, Other Vehicular',
'Distraction, Physical Surroundings',
'Distraction, Other Vehicular',
'Distraction, Poor Driving, Poor Driving',
'Physical Surroundings, Physical Surroundings',
'Poor Driving, Substance Abuse',
'Other Vehicular, Other Vehicular, Other Vehicular',
'Driver Behavior, Physical Surroundings',
'Distraction, Distraction, Poor Driving',
'Driver Behavior, Poor Driving',
'Poor Driving, Poor Driving, Poor Driving',
'Distraction, Distraction, Distraction, Physical Surroundings, Physical Surroundings',
'Defective Car, Poor Driving',
'Distraction, Distraction, Distraction',
'Driver Behavior, Driver Behavior, Driver Behavior',
'Distraction, Substance Abuse', 'Defective Car, Driver Behavior',
'Defective Car, Distraction',
'Defective Car, Other Vehicular, Other Vehicular',
'Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Phone', 'Defective Car, Defective Car',
'Driver Behavior, Substance Abuse',
'Distraction, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Distraction, Distraction, Distraction',
'Electronic Defective',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular, Substance Abuse',
'Defective Car, Defective Car, Poor Driving',
'Defective Car, Other Vehicular',
'Other Vehicular, Substance Abuse',
'Distraction, Distraction, Distraction, Poor Driving',
'Distraction, Other Vehicular, Other Vehicular',
'Other Vehicular, Other Vehicular, Poor Driving',
'Other Vehicular, Other Vehicular, Substance Abuse',
'Electronic Defective, Electronic Defective',
'Poor Driving, Substance Abuse, Substance Abuse',
'Distraction, Physical Surroundings, Physical Surroundings',
'Physical Surroundings, Physical Surroundings, Poor Driving',
'Substance Abuse, Substance Abuse, Substance Abuse',
'Other Vehicular, Physical Surroundings, Poor Driving',
'Physical Disability, Substance Abuse',
'Defective Car, Physical Surroundings',
'Driver Behavior, Other Vehicular, Other Vehicular',
'Distraction, Distraction, Distraction, Distraction, Distraction',
'Distraction, Distraction, Other Vehicular',
'Distraction, Other Vehicular, Poor Driving',
'Poor Driving, Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Physical Disability, Poor Driving',
'Physical Disability, Physical Surroundings, Physical Surroundings',
'Distraction, Poor Driving, Poor Driving, Poor Driving',
'Other Vehicular, Other Vehicular, Physical Surroundings',
'Electronic Defective, Electronic Defective, Electronic Defective',
'Distraction, Distraction, Distraction, Physical Surroundings',
'Other Vehicular, Other Vehicular, Poor Driving, Poor Driving',
'Driver Behavior, Driver Behavior, Physical Disability',
'Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Substance Abuse, Substance Abuse',
'Other Vehicular, Other Vehicular, Other Vehicular, Physical Disability',
'Other Vehicular, Other Vehicular, Other Vehicular, Poor Driving',
'Driver Behavior, Other Vehicular, Other Vehicular, Other Vehicular',
'Physical Disability, Poor Driving, Poor Driving',
'Defective Car, Substance Abuse',
'Other Vehicular, Physical Surroundings, Physical Surroundings, Physical Surroundings, Poor Driving',
'Defective Car, Physical Surroundings, Physical Surroundings',
'Defective Car, Distraction, Poor Driving',
'Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Driver Behavior, Poor Driving, Poor Driving',
'Defective Car, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Phone',
'Distraction, Distraction, Physical Surroundings, Physical Surroundings',
'Driver Behavior, Driver Behavior, Physical Surroundings',
'Distraction, Distraction, Driver Behavior',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular',
'Physical Surroundings, Substance Abuse',
'Distraction, Physical Surroundings, Poor Driving',
'Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Distraction, Distraction, Other Vehicular',
'Other Vehicular, Poor Driving, Poor Driving',
'Electronic Defective, Other Vehicular',
'Physical Surroundings, Poor Driving, Poor Driving',
'Driver Behavior, Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Other Vehicular, Poor Driving, Poor Driving, Poor Driving',
'Physical Disability, Physical Surroundings',
'Driver Behavior, Poor Driving, Poor Driving, Poor Driving',
'Other Vehicular, Physical Disability',
'Distraction, Distraction, Distraction, Distraction, Poor Driving',
'Defective Car, Distraction, Distraction',
'Distraction, Distraction, Physical Surroundings',
'Driver Behavior, Driver Behavior, Driver Behavior, Poor Driving, Poor Driving',
'Distraction, Distraction, Poor Driving, Poor Driving',
'Distraction, Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Driver Behavior, Other Vehicular, Poor Driving',
'Distraction, Driver Behavior, Other Vehicular, Other Vehicular',
'Driver Behavior, Physical Disability',
'Other Vehicular, Other Vehicular, Phone',
'Distraction, Other Vehicular, Physical Surroundings',
'Driver Behavior, Physical Surroundings, Physical Surroundings',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular, Poor Driving',
'Other Vehicular, Other Vehicular, Physical Disability',
'Driver Behavior, Other Vehicular, Other Vehicular, Other Vehicular, Poor Driving',
'Distraction, Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Driver Behavior, Poor Driving',
'Electronic Defective, Poor Driving, Poor Driving',
'Driver Behavior, Driver Behavior, Driver Behavior, Driver Behavior',
'Driver Behavior, Other Vehicular, Physical Surroundings',
'Distraction, Other Vehicular, Poor Driving, Poor Driving',
'Defective Car, Poor Driving, Poor Driving',
'Defective Car, Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular',
'Driver Behavior, Driver Behavior, Poor Driving, Poor Driving',
'Distraction, Driver Behavior, Driver Behavior, Driver Behavior',
'Phone, Poor Driving', 'Driver Behavior, Phone',
'Electronic Defective, Poor Driving',
'Other Vehicular, Other Vehicular, Other Vehicular, Substance Abuse',
'Electronic Defective, Physical Surroundings',
'Distraction, Distraction, Poor Driving, Poor Driving, Poor Driving',
'Distraction, Electronic Defective',
'Driver Behavior, Physical Surroundings, Poor Driving',
'Distraction, Distraction, Electronic Defective',
'Distraction, Other Vehicular, Other Vehicular, Poor Driving',
'Physical Disability, Physical Disability',
'Distraction, Driver Behavior, Driver Behavior',
'Distraction, Distraction, Physical Surroundings, Poor Driving',
'Electronic Defective, Other Vehicular, Other Vehicular',
'Driver Behavior, Driver Behavior, Poor Driving',
'Substance Abuse, Substance Abuse, Substance Abuse, Substance Abuse',
'Distraction, Physical Disability',
'Other Vehicular, Physical Surroundings, Physical Surroundings',
'Distraction, Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Phone, Physical Surroundings', 'Other Vehicular, Phone',
'Driver Behavior, Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Physical Surroundings, Physical Surroundings, Substance Abuse',
'Distraction, Distraction, Driver Behavior, Poor Driving, Poor Driving',
'Distraction, Other Vehicular, Substance Abuse',
'Defective Car, Distraction, Distraction, Other Vehicular',
'Distraction, Driver Behavior, Poor Driving, Poor Driving, Poor Driving',
'Defective Car, Other Vehicular, Physical Surroundings',
'Defective Car, Distraction, Other Vehicular',
'Defective Car, Physical Disability',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular, Physical Disability',
'Driver Behavior, Driver Behavior, Other Vehicular, Other Vehicular, Other Vehicular',
'Distraction, Driver Behavior, Physical Surroundings, Physical Surroundings, Poor Driving',
'Distraction, Distraction, Other Vehicular, Physical Surroundings',
'Distraction, Distraction, Distraction, Poor Driving, Poor Driving',
'Distraction, Distraction, Distraction, Distraction, Physical Surroundings',
'Distraction, Driver Behavior, Physical Surroundings',
'Driver Behavior, Driver Behavior, Other Vehicular',
'Other Vehicular, Other Vehicular, Other Vehicular, Other Vehicular, Physical Surroundings',
'Distraction, Distraction, Substance Abuse',
'Other Vehicular, Poor Driving, Poor Driving, Poor Driving',
'Defective Car, Phone',
'Defective Car, Substance Abuse, Substance Abuse',
'Driver Behavior, Electronic Defective',
'Distraction, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Distraction, Driver Behavior, Physical Disability',
'Distraction, Distraction, Other Vehicular, Other Vehicular',
'Defective Car, Distraction, Distraction, Distraction',
'Other Vehicular, Other Vehicular, Poor Driving, Poor Driving, Poor Driving',
'Driver Behavior, Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Defective Car, Physical Surroundings, Poor Driving',
'Other Vehicular, Other Vehicular, Other Vehicular, Physical Surroundings',
'Distraction, Distraction, Distraction, Distraction, Driver Behavior',
'Physical Surroundings, Poor Driving, Poor Driving, Poor Driving',
'Distraction, Driver Behavior, Other Vehicular, Poor Driving',
'Defective Car, Other Vehicular, Poor Driving',
'Driver Behavior, Other Vehicular, Substance Abuse',
'Poor Driving, Poor Driving, Substance Abuse',
'Distraction, Poor Driving, Substance Abuse',
'Distraction, Driver Behavior, Other Vehicular',
'Other Vehicular, Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Electronic Defective, Substance Abuse',
'Distraction, Distraction, Distraction, Driver Behavior',
'Defective Car, Distraction, Distraction, Distraction, Distraction',
'Defective Car, Other Vehicular, Other Vehicular, Physical Surroundings',
'Physical Surroundings, Physical Surroundings, Physical Surroundings, Poor Driving',
'Defective Car, Physical Surroundings, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Physical Surroundings, Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Substance Abuse, Substance Abuse, Substance Abuse, Substance Abuse, Substance Abuse',
'Driver Behavior, Poor Driving, Substance Abuse',
'Defective Car, Defective Car, Distraction',
'Driver Behavior, Driver Behavior, Substance Abuse',
'Other Vehicular, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Driver Behavior, Driver Behavior, Driver Behavior, Substance Abuse',
'Other Vehicular, Physical Disability, Substance Abuse',
'Defective Car, Physical Surroundings, Physical Surroundings, Poor Driving',
'Other Vehicular, Substance Abuse, Substance Abuse',
'Phone, Poor Driving, Poor Driving, Poor Driving, Poor Driving',
'Distraction, Distraction, Physical Disability',
'Driver Behavior, Driver Behavior, Other Vehicular, Other Vehicular',
'Driver Behavior, Driver Behavior, Driver Behavior, Driver Behavior, Driver Behavior',
'Poor Driving, Poor Driving, Poor Driving, Substance Abuse',
'Defective Car, Electronic Defective',
'Driver Behavior, Driver Behavior, Poor Driving, Poor Driving, Poor Driving',
'Distraction, Other Vehicular, Phone',
'Defective Car, Defective Car, Defective Car',
'Defective Car, Defective Car, Other Vehicular',
'Driver Behavior, Driver Behavior, Driver Behavior, Poor Driving',
'Phone, Phone',
'Physical Disability, Physical Disability, Physical Disability, Physical Disability, Physical Disability',
'Distraction, Other Vehicular, Physical Disability',
'Electronic Defective, Electronic Defective, Electronic Defective, Electronic Defective',
'Distraction, Physical Disability, Physical Disability',
'Other Vehicular, Other Vehicular, Physical Surroundings, Physical Surroundings',
'Distraction, Physical Disability, Poor Driving',
'Distraction, Physical Disability, Physical Disability, Physical Disability',
'Physical Disability, Physical Disability, Physical Disability',
'Physical Disability, Physical Disability, Physical Disability, Physical Disability',
'Electronic Defective, Physical Disability', 'Phone, Phone, Phone',
'Driver Behavior, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Driver Behavior, Substance Abuse, Substance Abuse',
'Defective Car, Electronic Defective, Electronic Defective',
'Other Vehicular, Other Vehicular, Other Vehicular, Physical Surroundings, Physical Surroundings',
'Distraction, Other Vehicular, Other Vehicular, Physical Disability, Physical Disability',
'Driver Behavior, Physical Disability, Physical Disability',
'Physical Disability, Physical Surroundings, Physical Surroundings, Physical Surroundings',
'Other Vehicular, Physical Disability, Physical Disability',
'Electronic Defective, Physical Disability, Physical Disability',
'Distraction, Distraction, Driver Behavior, Driver Behavior',
'Physical Disability, Physical Disability, Poor Driving',
'Distraction, Distraction, Physical Disability, Physical Disability',
'Driver Behavior, Driver Behavior, Physical Disability, Physical Disability',
'Electronic Defective, Physical Disability, Physical Disability, Physical Disability, Poor Driving',
'Distraction, Physical Disability, Physical Surroundings',
'Physical Disability, Physical Surroundings, Poor Driving',
'Physical Disability, Physical Disability, Physical Surroundings',
'Driver Behavior, Other Vehicular, Physical Disability',
'Other Vehicular, Other Vehicular, Substance Abuse, Substance Abuse',
'Driver Behavior, Other Vehicular, Physical Surroundings, Physical Surroundings',
'Other Vehicular, Physical Disability, Poor Driving',
'Distraction, Other Vehicular, Other Vehicular, Other Vehicular, Physical Disability',
'Distraction, Distraction, Distraction, Physical Disability',
'Defective Car, Defective Car, Defective Car, Defective Car',
'Physical Disability, Physical Disability, Poor Driving, Poor Driving',
'Phone, Substance Abuse',
'Driver Behavior, Electronic Defective, Poor Driving',
'Phone, Physical Disability',
'Defective Car, Defective Car, Other Vehicular, Other Vehicular',
'Physical Surroundings, Physical Surroundings, Physical Surroundings, Substance Abuse',
'Physical Disability, Physical Disability, Physical Disability, Physical Surroundings',
'Driver Behavior, Other Vehicular, Other Vehicular, Poor Driving',
'Electronic Defective, Electronic Defective, Physical Disability',
'Poor Driving, Poor Driving, Substance Abuse, Substance Abuse, Substance Abuse',
'Defective Car, Driver Behavior, Poor Driving',
'Distraction, Physical Disability, Substance Abuse',
'Physical Disability, Physical Disability, Substance Abuse',
'Other Vehicular, Physical Disability, Physical Surroundings',
'Physical Disability, Substance Abuse, Substance Abuse',
'Distraction, Physical Disability, Physical Disability, Physical Disability, Physical Disability',
'Other Vehicular, Substance Abuse, Substance Abuse, Substance Abuse',
'Other Vehicular, Poor Driving, Substance Abuse',
'Defective Car, Defective Car, Defective Car, Defective Car, Defective Car',
'Distraction, Other Vehicular, Other Vehicular, Physical Disability',
'Other Vehicular, Physical Disability, Physical Disability, Physical Disability',
'Physical Disability, Physical Disability, Physical Disability, Poor Driving',
'Driver Behavior, Physical Disability, Poor Driving',
'Distraction, Substance Abuse, Substance Abuse',
'Other Vehicular, Other Vehicular, Physical Disability, Physical Disability',
'Distraction, Physical Disability, Physical Disability, Poor Driving',
'Phone, Poor Driving, Poor Driving',
'Distraction, Electronic Defective, Electronic Defective',
'Driver Behavior, Electronic Defective, Electronic Defective',
'Driver Behavior, Physical Disability, Physical Surroundings',
'Electronic Defective, Other Vehicular, Physical Disability',
'Other Vehicular, Physical Disability, Physical Disability, Physical Disability, Physical Disability',
'Defective Car, Driver Behavior, Electronic Defective',
'Physical Disability, Physical Disability, Physical Disability, Poor Driving, Poor Driving',
'Physical Disability, Poor Driving, Poor Driving, Poor Driving',
'Other Vehicular, Other Vehicular, Other Vehicular, Physical Disability, Physical Disability',
'Electronic Defective, Physical Disability, Poor Driving',
'Distraction, Distraction, Distraction, Distraction, Other Vehicular',
'Distraction, Distraction, Other Vehicular, Other Vehicular, Other Vehicular',
'Defective Car, Physical Disability, Physical Disability',
'Driver Behavior, Other Vehicular, Other Vehicular, Physical Disability',
'Distraction, Other Vehicular, Physical Disability, Physical Disability',
'Driver Behavior, Physical Disability, Physical Disability, Physical Disability',
'Other Vehicular, Other Vehicular, Poor Driving, Substance Abuse',
'Distraction, Driver Behavior, Other Vehicular, Other Vehicular, Other Vehicular',
'Electronic Defective, Electronic Defective, Other Vehicular',
'Physical Disability, Physical Disability, Poor Driving, Poor Driving, Substance Abuse',
'Other Vehicular, Other Vehicular, Physical Disability, Poor Driving',
'Driver Behavior, Electronic Defective, Substance Abuse',
'Distraction, Distraction, Other Vehicular, Other Vehicular, Physical Disability',
'Distraction, Distraction, Distraction, Electronic Defective',
'Distraction, Electronic Defective, Other Vehicular',
'Electronic Defective, Electronic Defective, Electronic Defective, Poor Driving',
'Electronic Defective, Phone',
'Other Vehicular, Other Vehicular, Physical Disability, Physical Disability, Poor Driving',
'Defective Car, Poor Driving, Poor Driving, Poor Driving',
'Distraction, Driver Behavior, Physical Disability, Physical Disability, Physical Disability',
'Driver Behavior, Physical Disability, Physical Disability, Substance Abuse',
'Physical Disability, Physical Disability, Substance Abuse, Substance Abuse',
'Distraction, Electronic Defective, Poor Driving',
'Distraction, Electronic Defective, Physical Disability',
'Electronic Defective, Electronic Defective, Poor Driving',
'Distraction, Other Vehicular, Physical Disability, Poor Driving',
'Distraction, Electronic Defective, Physical Disability, Physical Disability',
'Distraction, Electronic Defective, Physical Surroundings',
'Distraction, Distraction, Physical Disability, Poor Driving',
'Other Vehicular, Physical Disability, Poor Driving, Poor Driving',
'Driver Behavior, Driver Behavior, Driver Behavior, Other Vehicular',
'Electronic Defective, Electronic Defective, Other Vehicular, Other Vehicular',
'Other Vehicular, Physical Disability, Physical Disability, Physical Disability, Poor Driving',
'Defective Car, Driver Behavior, Physical Disability',
'Defective Car, Defective Car, Substance Abuse, Substance Abuse',
'Physical Surroundings, Physical Surroundings, Poor Driving, Poor Driving',
'Defective Car, Distraction, Poor Driving, Poor Driving',
'Distraction, Distraction, Physical Disability, Physical Disability, Physical Disability',
'Physical Disability, Physical Disability, Physical Disability, Physical Surroundings, Substance Abuse',
'Driver Behavior, Physical Disability, Substance Abuse',
'Distraction, Driver Behavior, Substance Abuse',
'Distraction, Distraction, Distraction, Distraction, Physical Disability',
'Electronic Defective, Physical Disability, Physical Disability, Physical Disability',
'Driver Behavior, Driver Behavior, Physical Disability, Substance Abuse',
'Defective Car, Distraction, Driver Behavior',
'Electronic Defective, Electronic Defective, Electronic Defective, Electronic Defective, Electronic Defective',
'Distraction, Other Vehicular, Physical Disability, Physical Disability, Physical Disability',
'Defective Car, Driver Behavior, Physical Disability, Physical Disability, Poor Driving',
'Defective Car, Other Vehicular, Physical Disability',
'Distraction, Distraction, Distraction, Other Vehicular, Other Vehicular',
'Physical Disability, Poor Driving, Substance Abuse'], dtype=object)xxxxxxxxxximport matplotlib.pyplot as pltv, c = df.groupby(df['CONTRIBUTING FACTORS (SPECIFIC)']).size().index, df.groupby(df['CONTRIBUTING FACTORS (SPECIFIC)']).size().values plt.style.use('seaborn')plt.figure(figsize=(10, 10))plt.barh(v[(-c).argsort()][1:4], c[(-c).argsort()][1:4])ax = plt.gca()ax.invert_yaxis()plt.title('Contributing Factors', fontsize=25)ax.tick_params(axis='both', which='major', labelsize=25)plt.show()xxxxxxxxxxWhere does it happen?¶
xxxxxxxxxximport matplotlib.pyplot as pltplt.figure(figsize=(20,10))plt.bar(list(df.groupby('BOROUGH').size().index), df.groupby('BOROUGH').size().values)plt.title('Number of collisions for each borough (district)', fontsize=15)Text(0.5, 1.0, 'Number of collisions for each borough (district)')
xxxxxxxxxximport foliumfrom folium.plugins import HeatMap#coords = df.loc[df['Category'] == 'SEX OFFENSES, NON FORCIBLE']['location']\# .apply(lambda x : [float(y) for y in x.replace('POINT (','').replace(')','').split(' ')])\# .values.tolist()lat, lon = df[['LATITUDE', 'LONGITUDE']].mean(axis=0)ny_map = folium.Map([lat, lon], zoom_start = 11.75, tiles = "Stamen Toner")coords = df[['LATITUDE', 'LONGITUDE']].iloc[:500,:].values.tolist()# Plot it on the map#From the documentation:#radius (int, default 25) – Radius of each “point” of the heatmap#max_zoom (default 18) – Zoom level where the points reach maximum intensity (as intensity scales with zoom), equals maxZoom of the map by defaultHeatMap(coords,radius=15).add_to(ny_map)#The center of the heatmaps draw a lot of attention. Outliers are harder to spot.#That being said, when points are stacked, it's hard to see exactly how many there are. ny_mapxxxxxxxxxxWhen does it happen?¶
xxxxxxxxxxdf['CRASH TIMESTAMP'] = pd.to_datetime(df['CRASH DATE'] + ' ' + df['CRASH TIME'], format='%m/%d/%Y %H:%M')xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(df.groupby(df['CRASH TIMESTAMP'].dt.weekday).size().index, df.groupby(df['CRASH TIMESTAMP'].dt.weekday).size().values)plt.xticks(range(0,7), ['Monday','Tuesday','Wednesday','Thursday','Friday', 'Satuday', 'Sunday'], fontsize=10)plt.title('Time of Day', fontsize=15)plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(df.groupby(df['CRASH TIMESTAMP'].dt.month).size().index, df.groupby(df['CRASH TIMESTAMP'].dt.month).size().values)plt.xticks(range(1,13), ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])plt.title('Collisions per month', fontsize=15)plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(df.groupby(df['CRASH TIMESTAMP'].dt.year).size().index, df.groupby(df['CRASH TIMESTAMP'].dt.year).size().values)plt.xticks(range(2012, 2022))plt.title('Collisions per year', fontsize=15)plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(df.groupby(df['CRASH TIMESTAMP'].dt.hour).size().index, df.groupby(df['CRASH TIMESTAMP'].dt.hour).size().values)plt.xticks(range(0, 24), range(0, 24))ax = plt.gca()ax.tick_params(axis='both', which='major', labelsize=20)plt.title('Collisions per hour', fontsize=30)plt.show()xxxxxxxxxxLook at the hour for different categories¶
pd.read_csv('contributing_factors.csv', sep=';')['to'].unique()
xxxxxxxxxx#Baseline distribution.query_factors = ['right-of-way']df_query = df.loc[[any(y in x for y in query_factors) for x in df['CONTRIBUTING FACTORS']]]baseline = df.groupby(df['CRASH TIMESTAMP'].dt.hour).size() / len(df)query = df_query.groupby(df['CRASH TIMESTAMP'].dt.hour).size() / len(df_query)plt.figure(figsize=(20,10))plt.bar(range(0,24), query/baseline)plt.xticks(range(0,24), range(0,24))plt.axhline(1, c='r', ls='--')plt.show()xxxxxxxxxxJitter Plot¶
xxxxxxxxxxplt.figure(figsize=(20,10))plt.scatter(df['CRASH TIMESTAMP'].dt.minute, np.random.randn(len(df))+np.ones(len(df)), alpha=.005)plt.xticks(np.arange(0, 60, 1), [str(x).zfill(2) for x in np.arange(0, 60, 1)])plt.yticks([])plt.show()xxxxxxxxxxWhen do serious / or lethal crashes occur?¶
xxxxxxxxxxHere, a serious crash is defined as a crash where a person is injured or killed.
xxxxxxxxxxdf_serious = df.loc[(df['NUMBER OF PERSONS INJURED'] + df['NUMBER OF PERSONS KILLED']) > 0]df_lethal = df.loc[df['NUMBER OF PERSONS KILLED'] > 0]xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(range(0, 24), df_serious.groupby(df_serious['CRASH TIMESTAMP'].dt.hour).size() / df.groupby(df['CRASH TIMESTAMP'].dt.hour).size())plt.xlabel('Hour', fontsize=15)plt.ylabel('Risk of being serious', fontsize=15)plt.xticks(range(0,24))plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(range(0, 24), df_lethal.groupby(df_lethal['CRASH TIMESTAMP'].dt.hour).size() / df.groupby(df['CRASH TIMESTAMP'].dt.hour).size())plt.xlabel('Hour', fontsize=15)plt.ylabel('Risk of being lethal', fontsize=15)plt.xticks(range(0,24))plt.show()xxxxxxxxxxdf_lethal['CRASH TIMESTAMP'].dt.weekday667 1
805 2
1165 3
1706 4
1891 1
..
1762123 0
1763645 6
1763755 2
1765238 1
1765547 3
Name: CRASH TIMESTAMP, Length: 1851, dtype: int64xxxxxxxxxxWhen in the week do serious accidents occur?¶
xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar(range(0,24*7), df_serious.groupby([df_serious['CRASH TIMESTAMP'].dt.weekday, df_serious['CRASH TIMESTAMP'].dt.hour]).size() .unstack().fillna(0).values.reshape(-1,))plt.xlim(0, 24*7)plt.show()xxxxxxxxxxInvestigation into injury¶
xxxxxxxxxxinjury_columns = [x for x in df.columns if x.startswith('NUMBER OF ')]for injury in injury_columns: print(injury.title()) n, nocc = df.groupby(injury).size().index, df.groupby(injury).size().values for i, j in zip(n, nocc/nocc.sum()): print(f'{int(i)}, {j}') print('')Number Of Persons Injured 0, 0.7976347342723777 1, 0.15766959812722478 2, 0.02901464616144073 3, 0.009548993871829054 4, 0.0036027268882338347 5, 0.0014153799478841935 6, 0.0005772076263396938 7, 0.0002577508442786383 8, 0.00011119924204539758 9, 5.334992537438149e-05 10, 4.0494521669711256e-05 11, 2.1211416112705894e-05 12, 1.60692546308378e-05 13, 1.0284322963736192e-05 14, 3.21385092616756e-06 15, 4.499391296634584e-06 16, 4.499391296634584e-06 17, 2.571080740934048e-06 18, 2.571080740934048e-06 19, 1.928310555700536e-06 20, 1.285540370467024e-06 22, 1.928310555700536e-06 24, 1.928310555700536e-06 27, 6.42770185233512e-07 32, 6.42770185233512e-07 43, 6.42770185233512e-07 Number Of Persons Killed 0, 0.9988102232100962 1, 0.0011531386067463107 2, 2.8282106297010966e-05 3, 5.142201144911085e-06 4, 1.9283254293416567e-06 5, 6.427751431138856e-07 8, 6.427751431138856e-07 Number Of Pedestrians Injured 0, 0.9482208947011856 1, 0.04991509093176293 2, 0.0016409754065800993 3, 0.00017354616520823612 4, 2.8281597293194033e-05 5, 1.0284217197525104e-05 6, 5.784872173607871e-06 7, 1.9282907245359568e-06 9, 1.285527149690638e-06 13, 6.42763574845319e-07 15, 6.42763574845319e-07 27, 6.42763574845319e-07 Number Of Pedestrians Killed 0, 0.9993450239172326 1, 0.0006491912105937722 2, 5.142108598762552e-06 6, 6.42763574845319e-07 Number Of Cyclist Injured 0, 0.9762897372511059 1, 0.023490437606297026 2, 0.0002133975068486459 3, 5.784872173607871e-06 4, 6.42763574845319e-07 Number Of Cyclist Killed 0, 0.9999074420452223 1, 9.191519120288061e-05 2, 6.42763574845319e-07 Number Of Motorist Injured 0, 0.872163323653314 1, 0.0859908393335313 2, 0.026602056072123216 3, 0.009255795477772593 4, 0.0035223443901523477 5, 0.0013941541938394969 6, 0.0005585615465405822 7, 0.00024232186771668525 8, 0.0001086270441488589 9, 5.270661313731615e-05 10, 3.8565814490719133e-05 11, 2.1211197969895526e-05 12, 1.5426325796287654e-05 13, 1.0284217197525104e-05 14, 3.8565814490719135e-06 15, 3.2138178742265947e-06 16, 3.8565814490719135e-06 17, 2.571054299381276e-06 18, 2.571054299381276e-06 19, 1.285527149690638e-06 20, 1.285527149690638e-06 21, 6.42763574845319e-07 22, 1.285527149690638e-06 24, 1.9282907245359568e-06 30, 6.42763574845319e-07 43, 6.42763574845319e-07 Number Of Motorist Killed 0, 0.9995564931333567 1, 0.0004139397422003854 2, 2.2496725119586164e-05 3, 5.142108598762552e-06 4, 1.285527149690638e-06 5, 6.42763574845319e-07
xxxxxxxxxxCheck the Latitude and Longtitude¶
xxxxxxxxxxWe might have some outliers in latitude and longitude still...
xxxxxxxxxxplt.figure(figsize=(20,10))plt.scatter(df['LATITUDE'], df['LONGITUDE'], alpha=0.25)plt.axis('equal')plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.scatter(range(0, 366), df.loc[df['CRASH TIMESTAMP'].dt.year == 2020].groupby(df['CRASH TIMESTAMP'].dt.date).size().values, label='2020')plt.scatter(range(0, 365), df.loc[df['CRASH TIMESTAMP'].dt.year == 2019].groupby(df['CRASH TIMESTAMP'].dt.date).size().values, label='2019')plt.legend(fontsize=15, loc='lower left')plt.xlabel('Day of Year', fontsize=15)plt.ylabel('Number of Daily Crashes', fontsize=15)plt.show()xxxxxxxxxxplt.figure(figsize=(20,10))plt.bar((df['CRASH TIMESTAMP'].dt.year).unique(), df.groupby(df['CRASH TIMESTAMP'].dt.year).size())plt.xticks((df['CRASH TIMESTAMP'].dt.year).unique())plt.show()xxxxxxxxxxWhich factors mix?¶
xxxxxxxxxxcontributing_factors = np.unique(pd.read_csv('contributing_factors.csv', sep=';')['to'].to_numpy())xxxxxxxxxxcontributing_factorsarray(['accelerator defective', 'aggressive driving/road rage',
'alcohol involvement', 'animals action', 'backing unsafely',
'brakes defective', 'cell phone', 'driver inattention/distraction',
'driver inexperience', 'driverless/runaway vehicle', 'drugs',
'eating or drinking', 'failure to keep right',
'failure to yield right-of-way', 'fatigued/drowsy', 'fell asleep',
'following too closely', 'glare', 'headlights defective',
'illness', 'lane marking improper/inadequate',
'listening/using headphones', 'lost consciousness',
'obstruction/debris', 'other electronic device',
'other lighting defects', 'other vehicular',
'outside car distraction', 'oversized vehicle',
'passenger distraction', 'passing or lane usage improper',
'passing too closely', 'pavement defective', 'pavement slippery',
'pedestrian/bicyclist/other pedestrian error/confusion',
'physical disability', 'prescription medication',
'reaction to other uninvolved vehicle',
'reaction to uninvolved vehicle', 'shoulders defective/improper',
'steering failure', 'tinted windows', 'tire failure/inadequate',
'tow hitch defective',
'traffic control device improper/non-working',
'traffic control disregarded', 'turning improperly',
'unsafe lane changing', 'unsafe speed', 'unspecified',
'using on board navigation device', 'vehicle vandalism',
'view obstructed/limited', 'windshield inadequate'], dtype=object)xxxxxxxxxxi, c = df.groupby('CONTRIBUTING FACTORS').size().index, df.groupby('CONTRIBUTING FACTORS').size().valuesxxxxxxxxxx2042
xxxxxxxxxxxxxxxxxxxxDistraction Notebook¶
df['ZIP CODE'] = df['ZIP CODE'].astype(str).replace(' ','nan').astype(float)xxxxxxxxxxIntroduction Notebook¶
import numpy as npimport pandas as pdfrom sklearn.neighbors import NearestNeighborsfrom aux import *import timet1 = time.time()df = pd.read_csv('preprocessed_collisions.csv')t2 = time.time()print(f'Done doing the preprocessing. Time elapsed {t2-t1} seconds.')Done doing the preprocessing. Time elapsed 8.262746810913086 seconds.
df['YEAR'] = pd.to_datetime(df['CRASH DATE']).dt.yeardf['MONTH'] = pd.to_datetime(df['CRASH DATE']).dt.monthx
df3 = pd.DataFrame({'BOROUGH' : df.groupby('BOROUGH').size().index, 'values' : df.groupby('BOROUGH').size().values})df3['BOROUGH'] = df3['BOROUGH'].apply(lambda x : x.title())import plotly.express as pxfrom urllib.request import urlopenimport jsonwith urlopen('https://raw.githubusercontent.com/dwillis/nyc-maps/master/boroughs.geojson') as response: counties = json.load(response) import plotly.express as pxfig = px.choropleth_mapbox(df3, geojson=counties, locations='BOROUGH', color='values', featureidkey="properties.BoroName", color_continuous_scale="Viridis", range_color=(0, 500000), center={"lat": 40.730610, "lon": -73.935242}, labels={'values':'Number of crashes'}, mapbox_style="carto-positron", zoom=9 )fig.update_geos(fitbounds="locations", visible=False)fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})fig.show()xxxxxxxxxxWhere do they occur (zip code?)¶
x
import plotly.express as pxfrom urllib.request import urlopenimport jsonwith urlopen('https://raw.githubusercontent.com/fedhere/PUI2015_EC/master/mam1612_EC/nyc-zip-code-tabulation-areas-polygons.geojson') as response: counties = json.load(response) import plotly.express as pxfig = px.choropleth_mapbox(pd.DataFrame({'ZIP' : df.groupby('ZIP CODE').size().index, 'COUNT' : df.groupby('ZIP CODE').size().values}), geojson=counties, locations='ZIP', color='COUNT', featureidkey="properties.postalCode", color_continuous_scale="Viridis", range_color=(0, 27093), center={"lat": 40.730610, "lon": -73.935242}, labels={'values':'Number of crashes'}, mapbox_style="carto-positron", zoom=9 )fig.update_geos(fitbounds="locations", visible=False)fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})fig.show()import plotly.express as pxxxxxxxxxxxHeatmap¶
x
import plotly.express as pxfig = px.density_mapbox(df.iloc[:100,:], lat='LATITUDE', lon='LONGITUDE', radius=25, center=dict(lat=40.730610, lon=-73.935242), zoom=9, mapbox_style="carto-positron", width = 800, height = 800)fig.show()xxxxxxxxxxWhere do they happen?¶
df['YEAR'] = pd.to_datetime(df['CRASH DATE']).dt.yeardf['MONTH'] = pd.to_datetime(df['CRASH DATE']).dt.monthxxxxxxxxxxdf_test = pd.DataFrame({'BOROUGH' : [x[0].title() for x in df.groupby(['BOROUGH', 'YEAR']).size().index], 'YEAR' : [x[1] for x in df.groupby(['BOROUGH', 'YEAR']).size().index], 'COUNT' : df.groupby(['BOROUGH', 'YEAR']).size().values})#Remove 2012 and 2021.df_test = df_test.loc[df_test['YEAR'].apply(lambda x : x not in [2012, 2021])]import plotly.express as pxfrom urllib.request import urlopenimport jsonwith urlopen('https://raw.githubusercontent.com/dwillis/nyc-maps/master/boroughs.geojson') as response: counties = json.load(response) import plotly.express as pxfig = px.choropleth_mapbox(df_test, geojson=counties, locations='BOROUGH', color='COUNT', featureidkey="properties.BoroName", color_continuous_scale="Viridis", range_color=(0, 63949), animation_frame="YEAR", center={"lat": 40.730610, "lon": -73.935242}, labels={'values':'Number of crashes'}, mapbox_style="carto-positron", zoom=9, width = 800, height = 800 )fig.show()from urllib.request import urlopenxxxxxxxxxxdf_test = pd.DataFrame({'ZIP CODE' : [x[0] for x in df.groupby(['ZIP CODE', 'YEAR']).size().index], 'YEAR' : [x[1] for x in df.groupby(['ZIP CODE', 'YEAR']).size().index], 'COUNT' : df.groupby(['ZIP CODE', 'YEAR']).size().values})#Remove 2012 and 2021.df_test = df_test.loc[df_test['YEAR'].apply(lambda x : x not in [2012, 2021])]df_test = df_test.sort_values(by=['ZIP CODE', 'YEAR'])import plotly.express as pxfrom urllib.request import urlopenimport jsonwith urlopen('https://raw.githubusercontent.com/fedhere/PUI2015_EC/master/mam1612_EC/nyc-zip-code-tabulation-areas-polygons.geojson') as response: counties = json.load(response) import plotly.express as pxfig = px.choropleth_mapbox(df_test, geojson=counties, locations='ZIP CODE', color='COUNT', featureidkey="properties.postalCode", color_continuous_scale="Viridis", range_color=(0, df_test['COUNT'].max()), animation_frame="YEAR", category_orders={"YEAR": range(2013, 2021)}, center={"lat": 40.730610, "lon": -73.935242}, labels={'values':'Number of crashes'}, mapbox_style="carto-positron", zoom=9, width = 800, height = 800 )fig.show()x
!pip install jupyter-dashCollecting jupyter-dash Downloading jupyter_dash-0.4.0-py3-none-any.whl (20 kB) Requirement already satisfied: ipykernel in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (5.3.4) Requirement already satisfied: requests in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (2.25.1) Requirement already satisfied: ipython in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (7.20.0) Requirement already satisfied: flask in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (1.1.2) Collecting ansi2html Downloading ansi2html-1.6.0-py3-none-any.whl (14 kB) Requirement already satisfied: dash in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (1.19.0) Requirement already satisfied: retrying in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-dash) (1.3.3) Requirement already satisfied: dash-html-components==1.1.2 in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (1.1.2) Requirement already satisfied: future in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (0.18.2) Requirement already satisfied: plotly in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (4.14.3) Requirement already satisfied: dash-table==4.11.2 in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (4.11.2) Requirement already satisfied: dash-core-components==1.15.0 in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (1.15.0) Requirement already satisfied: dash-renderer==1.9.0 in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (1.9.0) Requirement already satisfied: flask-compress in /opt/anaconda3/lib/python3.7/site-packages (from dash->jupyter-dash) (1.9.0) Requirement already satisfied: Werkzeug>=0.15 in /opt/anaconda3/lib/python3.7/site-packages (from flask->jupyter-dash) (1.0.1) Requirement already satisfied: Jinja2>=2.10.1 in /opt/anaconda3/lib/python3.7/site-packages (from flask->jupyter-dash) (2.11.3) Requirement already satisfied: click>=5.1 in /opt/anaconda3/lib/python3.7/site-packages (from flask->jupyter-dash) (7.1.2) Requirement already satisfied: itsdangerous>=0.24 in /opt/anaconda3/lib/python3.7/site-packages (from flask->jupyter-dash) (1.1.0) Requirement already satisfied: MarkupSafe>=0.23 in /opt/anaconda3/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask->jupyter-dash) (1.1.1) Requirement already satisfied: brotli in /opt/anaconda3/lib/python3.7/site-packages (from flask-compress->dash->jupyter-dash) (1.0.9) Requirement already satisfied: traitlets>=4.1.0 in /opt/anaconda3/lib/python3.7/site-packages (from ipykernel->jupyter-dash) (5.0.5) Requirement already satisfied: appnope in /opt/anaconda3/lib/python3.7/site-packages (from ipykernel->jupyter-dash) (0.1.2) Requirement already satisfied: tornado>=4.2 in /opt/anaconda3/lib/python3.7/site-packages (from ipykernel->jupyter-dash) (6.1) Requirement already satisfied: jupyter-client in /opt/anaconda3/lib/python3.7/site-packages (from ipykernel->jupyter-dash) (6.1.7) Requirement already satisfied: pexpect>4.3 in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (4.8.0) Requirement already satisfied: jedi>=0.16 in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (0.17.2) Requirement already satisfied: backcall in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (0.2.0) Requirement already satisfied: pickleshare in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (0.7.5) Requirement already satisfied: decorator in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (4.4.2) Requirement already satisfied: pygments in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (2.7.4) Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (3.0.8) Requirement already satisfied: setuptools>=18.5 in /opt/anaconda3/lib/python3.7/site-packages (from ipython->jupyter-dash) (52.0.0.post20210125) Requirement already satisfied: parso<0.8.0,>=0.7.0 in /opt/anaconda3/lib/python3.7/site-packages (from jedi>=0.16->ipython->jupyter-dash) (0.7.0) Requirement already satisfied: ptyprocess>=0.5 in /opt/anaconda3/lib/python3.7/site-packages (from pexpect>4.3->ipython->jupyter-dash) (0.7.0) Requirement already satisfied: wcwidth in /opt/anaconda3/lib/python3.7/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython->jupyter-dash) (0.2.5) Requirement already satisfied: ipython-genutils in /opt/anaconda3/lib/python3.7/site-packages (from traitlets>=4.1.0->ipykernel->jupyter-dash) (0.2.0) Requirement already satisfied: python-dateutil>=2.1 in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter-dash) (2.8.1) Requirement already satisfied: jupyter-core>=4.6.0 in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter-dash) (4.7.1) Requirement already satisfied: pyzmq>=13 in /opt/anaconda3/lib/python3.7/site-packages (from jupyter-client->ipykernel->jupyter-dash) (20.0.0) Requirement already satisfied: six>=1.5 in /opt/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.1->jupyter-client->ipykernel->jupyter-dash) (1.15.0) Requirement already satisfied: chardet<5,>=3.0.2 in /opt/anaconda3/lib/python3.7/site-packages (from requests->jupyter-dash) (4.0.0) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/anaconda3/lib/python3.7/site-packages (from requests->jupyter-dash) (1.26.3) Requirement already satisfied: idna<3,>=2.5 in /opt/anaconda3/lib/python3.7/site-packages (from requests->jupyter-dash) (2.10) Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda3/lib/python3.7/site-packages (from requests->jupyter-dash) (2020.12.5) Installing collected packages: ansi2html, jupyter-dash Successfully installed ansi2html-1.6.0 jupyter-dash-0.4.0
xxxxxxxxxxPoor Driving Notebook¶
df['ZIP CODE'] = df['ZIP CODE'].astype(str).replace(' ','nan').astype(float)xxxxxxxxxx- notebook.ipynb
- introduction.ipynb
- Untitled.ipynb
- distractions.ipynb
- poor driving.ipynb
- aux.py
- contributing_factors.csv
xxxxxxxxxximport plotly.express as pxfrom jupyter_dash import JupyterDashimport dash_core_components as dccimport dash_html_components as htmlfrom dash.dependencies import Input, Output# Load Datadf = px.data.tips()# Build Appapp = JupyterDash(__name__)app.layout = html.Div([ html.H1("JupyterDash Demo"), dcc.Graph(id='graph'), html.Label([ "colorscale", dcc.Dropdown( id='colorscale-dropdown', clearable=False, value='plasma', options=[ {'label': c, 'value': c} for c in px.colors.named_colorscales() ]) ]),])# Define callback to update graph@app.callback( Output('graph', 'figure'), [Input("colorscale-dropdown", "value")])def update_figure(colorscale): return px.scatter( df, x="total_bill", y="tip", color="size", color_continuous_scale=colorscale, render_mode="webgl", title="Tips" )# Run app and display result inline in the notebookapp.run_server(mode='inline')